package com.canbot.u05.view;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.canbot.u05.R;

public class CenterDialogOne extends Dialog {

        private Context mContext;

        private String mTitleText;

        private String mLeftBtnText;

        private String mRightBtnText;

        private TextView mTVMsg;

        private String mString;

        private IButtonClickListerner mClickListenerInterface;

        private int mBkBtnLeft = 0, mBkBtnRight = 0;

        private final String TAG = "CenterDialog";

        /**
         * @param context
         * @param style
         * @param titleText          提示音的文本
         * @param leftBtnText        左边btn的文本
         * @param rightBtnText       右边btn的文本
         * @param leftBtnDrawableID  左边btn的背景
         * @param rightBtnDrawableID 右边btn的背景
         * @param IClickListener     点击事件的监听器
         */
        public CenterDialogOne(Context context, int style, String titleText,
                               String leftBtnText, String rightBtnText,
                               int leftBtnDrawableID, int rightBtnDrawableID,
                               IButtonClickListerner IClickListener) {
                super(context, style);
                this.mContext = context;
                this.mTitleText = titleText;
                this.mLeftBtnText = leftBtnText;
                this.mRightBtnText = rightBtnText;
                this.mClickListenerInterface = IClickListener;
                this.mBkBtnLeft = leftBtnDrawableID;
                this.mBkBtnRight = rightBtnDrawableID;
        }

        /**
         * btn采用默认的构造采用 *
         *
         * @param context
         * @param style
         * @param titleText
         * @param leftBtnText
         * @param rightBtnText
         * @param IClickListener
         */
        public CenterDialogOne(Context context, int style, String titleText,
                               IButtonClickListerner IClickListener) {
                super(context, style);
                this.mContext = context;
                this.mTitleText = titleText;
                this.mClickListenerInterface = IClickListener;
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                initView();
        }

        private void initView() {
                LayoutInflater layoutInflater = LayoutInflater.from(mContext);
                View viewDialog = layoutInflater.inflate(R.layout.dialog_centerone, null);
                setContentView(viewDialog);

                setCanceledOnTouchOutside(false);
                TextView mTextView = (TextView) viewDialog
                        .findViewById(R.id.tv_dialogtitle);
                Button mBtnRight = (Button) viewDialog
                        .findViewById(R.id.btn_dialogright);
                mTextView.setText(mTitleText);
                if (mBkBtnRight != 0) {
                        mBtnRight.setBackgroundResource(mBkBtnRight);
                }
                mBtnRight.setOnClickListener(new ClickListener());
        }


        @Override
        public void show() {
                super.show();
        }

        @Override
        public void cancel() {
                super.cancel();
        }

        private class ClickListener implements android.view.View.OnClickListener {

                @Override
                public void onClick(View v) {
                        cancel();
                        int viewID = v.getId();
                        switch (viewID) {
                                case R.id.btn_dialogright:
                                        if (mClickListenerInterface != null) {
                                                mClickListenerInterface.doBtnRight();
                                        }
                                        break;
                                default:
                                        break;
                        }
                }

        }
}
